﻿@model IEnumerable<BookStore.Models.Book>
@{
    Layout = "~/Views/Shared/_SubLayout.cshtml";
    ViewBag.Title = "Search";
}
<script>
    $(document).ready(function () {
        //Adding autocomplete to region input
        //Adding autocomplete to territoryDescription input
        $("#Search").autocomplete('@Url.Action("Books", "Search")', {
            //Don't fill the input while still selecting a value
            autoFill: false,
            //Only suggested values are valid
            mustMatch: true,
            //The comparison doesn't looks inside
            matchContains: false,
            //The number of query results to store in cache
            cacheLength: 12,
            //Callback wich will format items for autocomplete list
            formatItem: function (data, index) {
                //Display only descriptions in list
                return data[1];
            },
            //Callback which will format items for matching
            formatMatch: function (data, index, max) {
                //Match only descriptions
                return data[1];
            },
            //Callback which will format result
            formatResult: function (data, index, max) {
                //Display only description as result
                return data[1];
            }
            //Callback which will be called when user chooses value
        }).result(function (event, data, formatted) {
            //BookID is retuned in data[0]
        });
    });



</script>
<script>
    $(document).ready(function () {
        $('#Search').bind('keypress', function (e) {
            if (e.keyCode == 13) {
                //var value = $('#BookID').val()
                $('form').submit();
            }
        });
    });
</script>
@using (Html.BeginForm("Search", "Search"))
{
    @Html.TextBox("Search",string.Empty, new { style = "width:95%" })
}
<div class="title">
    <span class="title_icon">
        <img src= "@Url.Content("~/Content/Images/bullet1.gif")" alt="" title="" /></span>@ViewBag.Category
</div>
<div class="new_products">
    @if (ViewBag.Model != null)
    {
        foreach (var Bk in ViewBag.Model)
        {
            string sImageFile = string.Empty;
            if (File.Exists(Server.MapPath(string.Format("~/Content/Images/Book/{0}.jpg", Bk.BookCode))))
            {
                sImageFile = Bk.BookCode;
            }
            else
            {
                sImageFile = "nophoto";
            }
        
        <div class="new_prod_box">
            <a href="@Url.Action("Detail", "Home", new { ItemID = Bk.ID })">@Bk.BookName </a>
            <div class="new_prod_bg">
                <a href="@Url.Action("Detail", "Home", new { ItemID = Bk.ID })">
                    <img src="@Url.Content(string.Format("~/Content/Images/Book/{0}.jpg", sImageFile))" alt="" title="" class="thumb" border="0" /></a>
            </div>
        </div>
        }
    }
    else
    {
        <div>No Books Found</div>
    }
</div>
